<?php
class Clients_model extends CI_Model {

    var $id = '';
    var $name = '';
    var $ruc = '';
    var $address = '';
    var $telephone = '';
    var $email = '';
    private $_tabla = 'clients';

    function __construct() {
        // Call the Model constructor
        parent::__construct();
    }

    public function getAll()
    {
        $this->db->select();
        $this->db->where('status', 1);
        $query = $this->db->get($this->_tabla);
        return $query->result();
    }
    
    
    
   public function search($ruc = null, $name = null, $address = null, $telephone = null, $email= null)
    {
        $query = $this->db;
        if (isset($ruc) && $ruc != '') {
            $query = $query->like($this->_tabla.'.ruc', $ruc);
        }
        if (isset($name) && $name != '') {
            $query = $query->like($this->_tabla.'.name', $name);
        }
         if (isset($address) && $address != '') {
            $query = $query->like($this->_tabla.'.address', $address);
        }
         if (isset($telephone) && $telephone != '') {
            $query = $query->like($this->_tabla.'.telephone', $telephone);
        }
        if (isset($email) && $email != '') {
            $query = $query->like($this->_tabla.'.email', $email);
        }
        
        
        $query = $query->where($this->_tabla.'.status', 1);
        $query = $query->get($this->_tabla);
        $rs = $query->result();
        return $rs;
        
       
    }
    
    
    
    public function find($id)
    {
        $query = $this->db->where('id = '.$id)->get($this->_tabla);
        $rs = $query->result();
        if (isset($rs[0])) {
            return $rs[0];
        } 
        return false;
    }
    
      public function update($id, $data)
        {
//            if($data['id'] == false) {
//                unset($data['id']);
//            }
//            if ($data['insert_date'] == false) {
//                unset($data['insert_date']);
//            }
            
            
            $this->db->where('id', $id);
            $this->db->update($this->_tabla, $data);
            return true;
        }
    
        
        
    public function add($data)
    {
        $data['create'] = date('Y-m-d H:i:s');
       return $this->db->insert($this->_tabla, $data);
        
    }
    
    public function delete($id)
    {
        $this->db->where('id', $id);
        $this->db->update($this->_tabla, array('status' => 0));
        return true;
    }
    
    
    
    
    
    
    
    
}